package com.aigou.admin.service.impl;

import com.aigou.admin.dao.SalesDao;
import com.aigou.admin.dao.Shop_cart_productDao;
import com.aigou.admin.dao.impl.SalesDaoImpl;
import com.aigou.admin.dao.impl.Shop_cart_productDaoImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Shop_cart_product;
import com.aigou.admin.entity.User;
import com.aigou.admin.service.Shop_cart_productService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: May
 * @Date: 2024/12/3 17:13
 * @Version: 1.0
 */
@Service
@AllArgsConstructor
public class Shop_cart_productServiceImpl implements Shop_cart_productService {

    private final Shop_cart_productDao shopCartProductDao;

    @Override
    public List<Shop_cart_product> findAll() {
        return shopCartProductDao.selectAll();
    }

    @Override
    public Shop_cart_product findById(String id) {
        return shopCartProductDao.selectById(id);
    }

    @Override
    public Boolean save(Shop_cart_product shopCartProduct) {
        return shopCartProductDao.insert(shopCartProduct);
    }

    @Override
    public Boolean update(Shop_cart_product shopCartProduct) {
        return shopCartProductDao.update(shopCartProduct);
    }

    @Override
    public Boolean remove(String id) {
        return shopCartProductDao.delete(id);
    }

    @Override
    public PageEntity<Shop_cart_product> findUserPage(Integer current, Integer pageSize) {
        //查询用户总数 count(*)
        int total = shopCartProductDao.selectUserCount();
        //分页查询用户数据 limit
        List<Shop_cart_product> shopCartProducts = shopCartProductDao.selectUserLimit((current-1) * pageSize,pageSize);
        //发送数据给前端
        PageEntity<Shop_cart_product> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(shopCartProducts);
        return pageEntity;
    }

}
